package com.springboot5.demo.health;

import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.health.Health;
import org.springframework.boot.actuate.health.Status;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class MyComHealthIndicator  extends AbstractHealthIndicator {
    //编写我们真实的检查方法
    @Override
    protected void doHealthCheck(Health.Builder builder) throws Exception {
        Map<String ,Object> map=new HashMap<>();
        if(1==1){
            //builder.up();//健康
            builder.status(Status.UP);
            map.put("count",1) ;
            map.put("ms",100);
        }else{
            //builder.down();//不健康
            builder.status(Status.DOWN);
            map.put("error","连接超时");
            map.put("ms",3000);
        }
        builder.withDetail("code",1001).withDetails(map);
    }
}
